﻿namespace SignalR.Web.Models
{
    public class OnlineUser
    {
        public string ConnectionId { get; set; }
		public string GroupName { get; set; }
		public string UserName { get; set; } = string.Empty;
        public string ActiveStatus { get; set; } = string.Empty;
    }
	public class ResultModel
	{
		public int Code { get; set; }
		public string Msg { get; set; }
		public List<OnlineUser> OnlineUser { get; set; }
	}
	public class WebConst
    {
        public static List<OnlineUser> OnlineUserList { get; set; } = new List<OnlineUser>();

        public static OnlineUser? GetOnlineUser(string username)
        {
           return OnlineUserList.FirstOrDefault(c => c.UserName == username);
        }
        public static void AddOnlineUser(OnlineUser user)
        {
            var info = OnlineUserList.FirstOrDefault(c => c.UserName == user.UserName);
            if (info != null)
            {
                OnlineUserList = OnlineUserList.Where(c => c.UserName != user.UserName).ToList();
            }
            OnlineUserList.Add(user);
        }
        public static void DeleteOnlineUser(OnlineUser user)
        {
            var info = OnlineUserList.FirstOrDefault(c => c.UserName == user.UserName);
            if (info != null)
            {
                OnlineUserList= OnlineUserList.Where(c=>c.UserName != user.UserName).ToList();
            }
        }
    }

}
